﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Foundation;
using Yinyue200.Sharp2D.Interop;

namespace Yinyue200.Sharp2D.Direct2D.Effects
{
    /// <summary>
    /// Enumeration type that specifies how to process pixels that lie outside the input
    /// image.
    /// </summary>
    public enum EffectBorderMode
    {
        /// <summary>
        /// Pixels outside the input image are treated as transparent black, resulting in
        ///     a soft edge after processing.
        /// </summary>
        Soft = 0,
        /// <summary>
        /// The effect clamps to the size of the input image.
        /// </summary>
        Hard = 1
    }
    public class GaussianBlurEffect : Effect
    {
        public GaussianBlurEffect()
        {
            Name = "GaussianBlurEffect";
            SetBoxedProperty("StandardDeviation", Convert(PropertyValueOwner.CreateSingle(3.0f)), GRAPHICS_EFFECT_PROPERTY_MAPPING.GRAPHICS_EFFECT_PROPERTY_MAPPING_DIRECT);
            SetBoxedProperty("Optimization", Convert(PropertyValueOwner.CreateUInt32(1)), GRAPHICS_EFFECT_PROPERTY_MAPPING.GRAPHICS_EFFECT_PROPERTY_MAPPING_DIRECT);
            SetBoxedProperty("BorderMode", Convert(PropertyValueOwner.CreateUInt32(0)), GRAPHICS_EFFECT_PROPERTY_MAPPING.GRAPHICS_EFFECT_PROPERTY_MAPPING_DIRECT);

        }

        public override void GetEffectId(out Guid id)
        {
            id = SharpDX.Direct2D1.Effect.GaussianBlur;
        }

        public float BlurAmount
        {
            get
            {
                return (float)GetProperty("StandardDeviation");
            }
            set
            {
                SetProperty("StandardDeviation", Convert(PropertyValueOwner.CreateSingle(value)));
            }
        }

        public uint Optimization
        {
            get
            {
                return (uint)GetProperty(nameof(Optimization));
            }
            set
            {
                SetProperty(nameof(Optimization), Convert(PropertyValueOwner.CreateUInt32(value)));
            }
        }


        public EffectBorderMode BorderMode
        {
            get
            {
                return (EffectBorderMode)(uint)GetProperty(nameof(BorderMode));
            }
            set
            {
                SetProperty(nameof(BorderMode), Convert(PropertyValueOwner.CreateUInt32((uint)value)));
            }
        }
    }
}
